#define _CRT_SECURE_NO_WARNINGS 1
#include <string>
class Solution {
public:
    bool panduan(char str)
    {
        if (str <= '9' && str >= '0')
            return true;
        else
            return false;
    }
    int myAtoi(string str) {
        int tmp = 0;
        int flag = 1;
        int i = 0;
        while (str[i] == ' ')
        {
            i++;
        }
        if (str[i] == '-' || str[i] == '+')
        {
            if (str[i] == '-')
                flag = -1;
            if (str[i] == '+')
                flag = 1;
            i++;
        }
        if (!panduan(str[i]))
        {
            return 0;
        }
        while (panduan(str[i]) && i < str.size())
        {
            if (tmp < INT_MAX / 10 || tmp == INT_MAX / 10 && str[i] <= '7')
            {
                tmp = tmp * 10 + (str[i] - '0');
                i++;
            }
            else
            {
                if (flag == 1)
                    return INT_MAX;
                else
                    return INT_MIN;
            }
        }
        return tmp * flag;

    }
};